







<template>
  <div class="view-container">
    <!-- 展示 -->
    <!-- @select="selectDs" -->

      <el-table
        ref="multipleTable"
        :data="tableData"
        style="width: 100%"
        border
        stripe
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
      >
        <!--  :class="{ 'el-icon-document': isActive, 'el-icon-folder-opened': hasError }" -->
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column sortable label="名称" @click.stop="qwer">
          <template slot-scope="scope">
            <i :class="scope.row.fold ? 'el-icon-folder-opened' : 'el-icon-document' "></i>
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column
          prop="updateTime"
          :formatter="updateTimeFmt"
          label="修改日期"
          width="200"
          align="center"
          sortable
        ></el-table-column>
        <el-table-column sortable prop="creatorName" label="添加入" width="150" align="center"></el-table-column>
        <el-table-column label="排序" width="120" align="center">
          <el-button icon="el-icon-top" circle @click.stop="qwe"></el-button>
          <el-button icon="el-icon-bottom" circle @click.stop="qwe"></el-button>
        </el-table-column>
      </el-table>

  </div>
</template>


<script>
  import changeapi from "@/api/dangan/dangan";
  import danganXZK from "@/api/dangan/bumenselect/danganXZK";
  import danganRY from "@/api/dangan/renyuanselect/danganRY";
  import xinzengdangan from "@/api/dangan/xinzengdangan/danganXinzeng";
  import fileapi from "@/api/dangan/fileadd/addfile";

  export default {
    data() {
      return {
        tableData: [], // 列表组
        XZKdata: {}, //部门组
        RYdata: [], //人员组
        delsS: [], //删除数据组,
        drawer: false,
        isActive: false,
        hasError: true,
        selpid: "",
        buttShow:true,
        updata: false,
        upda: [], //文件查询组
        files: [], //上传文件组

        flieID: "00000000-0000-0000-0000-000000000000",

        fjiid: "00000000-0000-0000-0000-000000000000", //父级id

        formInline: {
          region: "",
          user: ""
        },
        value1: "",
        multip: true,

        //添加文件组
        user: {
          foldName: "",
          shareUserIdList: [],
          shareDepartmentIdList: [],
          pid: ""
        },

        fujiClass: {},

        //添加档案组
        danganuser: {
          dangAnContent: "",
          dangAnName: "",
          dangAnStarttime: "",
          foldId: "",
          projectName: "",
          shareDepartmentIdList: [],
          shareUserIdList: [],
          sortIndex: 1
        },

        centerDialogVisible: false,
        centerDialogVisibleS: false,
        dialogVisibleSS: false,
        centerDialogVisibleBB: false,
        multipleSelected: [], //部门select数据组
        multipleSelection: [], //人员select数据组
        updateAlls: {}, //编辑档案组
        filedihiz: "", //文件地址
        fileList: [
          {
            name: "food.jpeg",
            url:
              "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a17cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100"
          },
          {
            name: "food2.jpeg",
            url:
              "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a17cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100"
          }
        ]
      };
    },

    //生命周期
    created() {
      this.fetchdata(); //查询方法
      this.XZKlist(); //部门select查询方法
      this.RYdataa(); //人员select查询方法
      this.FujiRowClick()
    },
    methods: {
      qwe() {},
      qwer() {
        this.handleRowClick();
      },
      resetForm() {
        this.formInline.user = "";
        this.fetchdata();
      },

      //点击查询ID
      handleRowClick(row, column, event) {
        console.log(row);

        if (row.fold) {
          this.$refs["multipleTable"];

          this.danganuser.foldId = row.id;
          this.user.id = row.id;
          this.flieID = row.id;

          changeapi.updateSeAll(row.id).then(res => {
            this.user = res.result;
            this.fjiid = this.user.pid;
            console.log(this.fjiid);
            sessionStorage.setItem("id", this.fjiid);
          });

          // this.selpid = row.pid ? row.pid : '00000000-0000-0000-0000-000000000000';
          changeapi.cilList(this.flieID).then(res => {
            this.tableData = res.result;
          });
          this.buttShow=true
          console.log(this.fjiid);
          return;
        }

        this.danganAllc(row.id);

        // cilList
      },

      //点击返回上级
      FujiRowClick() {

        console.log("B父级"+this.fjiid);
        changeapi.FjiList(this.fjiid).then(res => {
          this.tableData = res.result;
        });

        if (this.fjiid=="00000000-0000-0000-0000-000000000000") {
          this.buttShow=false
          return
        }

        changeapi.updateSeAll(this.fjiid).then(res => {

          this.user = res.result;
          this.fjiid = this.user.pid;
          console.log("A父级"+this.fjiid);
        });

      },

      handleSelectionChange(arr) {
        this.delsS = [];
        this.upda = [];
        for (const val of arr) {
          this.delsS.push({ fold: val.fold, id: val.id });
          this.upda.push(val.id);
        }
      },
      //时间格式
      updateTimeFmt(row) {
        return new Date(row.updateTime).toLocaleString();
      },
      //部门select
      XZKlist() {
        danganXZK.getBumen().then(res => {
          this.XZKdata = res.result;
          console.log(this.XZKdata);
        });
      },
      //人员select
      RYdataa() {
        danganRY.getRenYuan().then(res => {
          this.RYdata = res.result;
        });
      },

      //查询列表
      fetchdata() {
        console.log(this.tableData);
        // id = id ? id : this.fjiid
        // console.log(id);

        changeapi.getList(this.fjiid, this.formInline.user).then(res => {
          // console.log(this.formInline.user);

          this.tableData = res.result;
        });

        this.user.id = "00000000-0000-0000-0000-000000000000";
        this.flieID = "00000000-0000-0000-0000-000000000000";
      },

      //查询档案详情
      danganAllc(id) {
        this.drawer = true;
        //档案详情
        changeapi.danganAlls(id).then(res => {
          this.danganuser = res.result;
        });
      },

      //添加文件夹
      add() {
        this.user.pid = this.flieID;
        changeapi.add(this.user).then(res => {
          console.log(this.user);

          this.$message.success("添加成功");
          console.log(this.user);

          (this.user.foldName = ""),
            (this.user.shareUserIdList = []),
            (this.user.shareDepartmentIdList = []),
            (this.user.pid = ""),
            (this.centerDialogVisible = false);
          changeapi.cilList(this.flieID).then(res => {
            this.tableData = res.result;
          });
        });
      },

      fileUpdate() {
        changeapi.fileUpdate(this.user).then(res => {
          this.$message.success("编辑成功");
          this.centerDialogVisible = false;
          this.updata = true;
          this.fetchdata();
        });
      },

      yidong() {},

      yindongs() {
        console.log(this.danganusers);
        changeapi.danganUpdate(this.danganusers).then(res => {
          this.$message.success("编辑成功");
          this.centerDialogVisible = false;
          this.updata = true;
          this.fetchdata();
        });
      },

      danganUpdats() {
        console.log(this.danganuser);

        changeapi.danganUpdate(this.danganuser).then(res => {
          this.$message.success("编辑成功");
          this.centerDialogVisible = false;
          this.updata = true;
          this.fetchdata();
        });
      },

      //添加档案
      danganadd() {
        this.fileaddsd();
        // this.danganuser
        this.danganuser.foldId = this.flieID;
        console.log(this.danganuser);

        xinzengdangan
          .danganadds(this.danganuser)
          .then(res => {
            this.$message.success("添加成功");
            this.centerDialogVisibleS = false;
            changeapi.cilList(this.flieID).then(res => {
              this.tableData = res.result;
            });
            this.danganuser.dangAnContent = "";
            this.danganuser.dangAnName = "";
            this.danganuser.dangAnStarttime = "";
            this.danganuser.foldId = "";
            this.danganuser.projectName = "";
            this.danganuser.shareDepartmentIdList = [];
            this.danganuser.shareUserIdList = [];
          })

          // this.sortIndex:1
          .catch(err => {
            console.log("添加失败");
          });
      },

      //文件上传
      fileaddtd(response) {
        this.filedihiz = response;
      },

      //上传文件
      fileaddsd() {
        fileapi.fileaddts(this.file).then(res => {
          if (res.success) {
            this.$message.success("上传成功");
          }
        });
      },

      delC() {
        console.log(this.fjiid);

        if (!this.delsS.length) {
          this.$message.info("请选择一项");
          return;
        }

        this.dialogVisibleSS = true;
      },

      //删除文件夹
      delS() {
        console.log(this.fjiid);

        changeapi
          .danandel(this.delsS)
          .then(res => {
            this.$message.success("删除成功");

            this.fetchdata();
          })
          .catch(err => {
            this.$message.success("删除失败");
            this.fetchdata();
          });
        this.dialogVisibleSS = false;
        this.fetchdata();
      },

      //文件夹详情查询
      updateAll() {
        if (!this.upda.length) {
          this.$message.info("请选择一项");
          return;
        }
        if (this.upda.length > 1) {
          this.$message.info("只能选一项");
          return;
        }

        this.updata = true;
        for (let item of this.tableData) {
          if (item.id === this.upda[0] && item.fold) {
            changeapi.updateSeAll(this.upda).then(res => {
              this.user = res.result;
            });

            this.centerDialogVisible = true;

            return;
          }
        }

        //档案详情
        changeapi.danganAlls(this.upda).then(res => {
          this.danganuser = res.result;
        });

        this.centerDialogVisibleS = true;
        this.centerDialogVisibleBB = true;
      },

      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },

      //复选框事件
      selectDs(arr) {
        this.delsS = [];
        this.upda = [];
        for (const val of arr) {
          this.delsS.push({ fold: val.fold, id: val.id });
          this.upda.push(val.id);
        }
      },

      handleClose(done) {
        this.$confirm("确认关闭？")
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      handleRemove(file, fileList) {},
      handlePreview(file) {},
      handleExceed(files, fileList) {
        this.$message.warning(
          `当前限制选择 3 个文件，本次选择了 ${
            files.length
          } 个文件，共选择了 ${files.length + fileList.length} 个文件`
        );
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${file.name}？`);
      }
    }
  };
</script>


<style scoped lang="scss">

  .formcha {
    margin-top: 10px;
  }
</style>
